package com.example.shaoying.yuejian.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.shaoying.yuejian.R;
import com.example.shaoying.yuejian.javabean.Game;

import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2017/9/29.
 */

public class GameAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List<Game> mDataList;
    private LayoutInflater mLayoutInflater;

    public GameAdapter(Context mContext, List<Game> mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView name;
        ImageView img;
        public ViewHolder(View itemView) {
            super(itemView);
            name= (TextView) itemView.findViewById(R.id.game_title);
            img= (ImageView) itemView.findViewById(R.id.game_pic);
        }
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=mLayoutInflater.from(parent.getContext()).inflate(R.layout.gameitem,parent,false);
        return new ViewHolder(view);
    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Game data=mDataList.get(position);
        if(data!=null){
            ViewHolder viewHolder=(ViewHolder) holder;
            viewHolder.name.setText(data.getName());
            Picasso.with(mContext).load("http://172.24.10.175/workout/Uploads/"+data.getThumb()).resize(350,150).centerCrop().into(viewHolder.img);
        }
    }


    @Override
    public int getItemCount() {
        return mDataList.size();
    }
}
